#include "Deck.h"
#include "Card.h"

#include <algorithm>
#include <random>
#include <ctime>

Deck::Deck(void)
{
}

Deck::~Deck(void)
{
	if(deck.size() > 0)
		ResetDeck();
}

void Deck::FillDeck()
{
	for(int x = 0; x < 4; ++x)
	{
		for(int y = 0; y < 13; ++y)
		{
			Card* card = new Card;
			std::string tmpSuit;
			std::string tmpValue;
			int tmpActual;

			switch(x)
			{
			case 0:
				tmpSuit = "of Spades";
				break;
			case 1:
				tmpSuit = "of Hearts";
				break;
			case 2:
				tmpSuit = "of Clubs";
				break;
			case 3:
				tmpSuit = "of Diamonds";
				break;
			}

			switch(y)
			{
			case 0:
				tmpValue = "Two ";
				break;
			case 1:
				tmpValue = "Three ";
				break;
			case 2:
				tmpValue = "Four ";
				break;
			case 3:
				tmpValue = "Five ";
				break;
			case 4:
				tmpValue = "Six ";
				break;
			case 5:
				tmpValue = "Seven ";
				break;
			case 6:
				tmpValue = "Eight ";
				break;
			case 7:
				tmpValue = "Nine ";
				break;
			case 8:
				tmpValue = "Ten ";
				break;
			case 9:
				tmpValue = "Jack ";
				break;
			case 10:
				tmpValue = "Queen ";
				break;
			case 11:
				tmpValue = "King ";
				break;
			case 12:
				tmpValue = "Ace ";
				break;
			}

			tmpActual = y + 2;

			if(tmpActual > 10)	tmpActual = 10;

			card->actualValue = tmpActual;
			card->actualCard = tmpValue + tmpSuit;
			deck.push_back(card);
		}
	}
}

void Deck::ResetDeck()
{
	for(unsigned int x = 0; x < deck.size(); ++x)
	{
		Card* tmpCard = deck[x];
		delete tmpCard;
	}
	deck.clear();
}

void Deck::ShuffleDeck()
{
	srand((unsigned int)time(NULL));

	std::random_shuffle(deck.begin(), deck.end());
}